import java.util.HashSet;
import java.util.Set;

/**
 * @ClassName LC219
 * @Author ykx
 * @Date 2024/6/29 16:52
 * @Version 1.0
 */
public class LC219 {
    public static void main(String[] args) {
        LC219 lc219 = new LC219();
        System.out.println(lc219.containsNearbyDuplicate(new int[]{99, 99}, 2));
    }

    public boolean containsNearbyDuplicate(int[] nums, int k) {

        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < nums.length; i++) {
            if (i <= k) {
                if (!set.add(nums[i])) {
                    return true;
                }
            } else {
                set.remove(nums[i - k - 1]);
                if (!set.add(nums[i])) {
                    return true;
                }
            }
        }
        return false;
    }

}
